set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)

add_definitions(-DUTKWIDGET_LIBRARY)
add_definitions(-DHAVE_CONFIG_H)

# Find the Qt library
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Gui Core Xml Network Svg)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Gui Core Xml Network Svg)

#生成ts文件的文件夹
set(TS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/translations")

set(TS_FILES
    "${TS_DIR}/utkwidget_zh_CN.ts"
    "${TS_DIR}/utkwidget_en.ts"
)

#模拟更新和发布的命令代码
find_program(LUPDATE_EXECUTABLE lupdate)

#生成ts和qm文件
foreach(_ts_file ${TS_FILES})
    execute_process(
        COMMAND ${LUPDATE_EXECUTABLE} -recursive ${CMAKE_CURRENT_SOURCE_DIR} -ts ${_ts_file})
endforeach()

FILE(GLOB HEADERS
    ${CMAKE_CURRENT_SOURCE_DIR}/*.h
    ${CMAKE_CURRENT_SOURCE_DIR}/dialog/*.h
    ${CMAKE_CURRENT_SOURCE_DIR}/widgets/*.h
    ${CMAKE_CURRENT_SOURCE_DIR}/style/*.h
    ${CMAKE_CURRENT_SOURCE_DIR}/effect/*.h
    ${CMAKE_CURRENT_SOURCE_DIR}/singleapplication/*.h
    ${CMAKE_CURRENT_SOURCE_DIR}/logger/*.h
    ${CMAKE_CURRENT_SOURCE_DIR}/zip/*.h
    ${CMAKE_CURRENT_SOURCE_DIR}/modelview/*.h
    ${CMAKE_CURRENT_SOURCE_DIR}/qrencode/*.h
    ${CMAKE_CURRENT_SOURCE_DIR}/qhotkey/qhotkey.h
    ${CMAKE_CURRENT_SOURCE_DIR}/qhotkey/qhotkey_p.h
)

FILE(GLOB SOURCES
    ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/dialog/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/widgets/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/style/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/effect/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/singleapplication/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/logger/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/zip/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/modelview/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/qrencode/*.c
    ${CMAKE_CURRENT_SOURCE_DIR}/qhotkey/qhotkey.cpp
)

set(PROJECT_SOURCES
    ${HEADERS}
    ${SOURCES}
)

if(APPLE)
    set(PROJECT_SOURCES
        ${PROJECT_SOURCES}
        ${CMAKE_CURRENT_SOURCE_DIR}/qhotkey/qhotkey_mac.cpp
    )
elseif(WIN32)
    set(PROJECT_SOURCES
        ${PROJECT_SOURCES}
        ${CMAKE_CURRENT_SOURCE_DIR}/qhotkey/qhotkey_win.cpp
    )
else()
    set(PROJECT_SOURCES
        ${PROJECT_SOURCES}
        ${CMAKE_CURRENT_SOURCE_DIR}/qhotkey/qhotkey_x11.cpp
    )
endif()

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_resources(qrc_FILES ${CMAKE_CURRENT_SOURCE_DIR}/utkwidgetres.qrc)
    add_library(utkwidget SHARED ${PROJECT_SOURCES} ${qrc_FILES})
else()
    qt5_add_resources(qrc_FILES ${CMAKE_CURRENT_SOURCE_DIR}/utkwidgetres.qrc)
    add_library(utkwidget SHARED ${PROJECT_SOURCES} ${qrc_FILES})
endif()

target_link_libraries(utkwidget PRIVATE
        Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Svg
        Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Xml
        Qt${QT_VERSION_MAJOR}::GuiPrivate
        Qt${QT_VERSION_MAJOR}::WidgetsPrivate
)
